package com.ipt.frm.pw;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ipt.frm.pw.Enumeraciones.TipoMensajes;
import com.ipt.frm.pw.beans.Mensaje;

/**
 * Servlet implementation class LogoutServlet
 */
public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	static Properties propertiesMsg;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LogoutServlet() {
        super();
    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
    		throws ServletException, IOException {
    	
    	propertiesMsg = (Properties) getServletContext().getAttribute("propertiesMsg");
    	HttpSession session = request.getSession();
    	Mensaje mensaje= new Mensaje(TipoMensajes.EXITO,MessageFormat.format(propertiesMsg.getProperty("logout.success"),session.getAttribute("username")));
    	session.invalidate();
    	request.setAttribute("MSG",mensaje);
    	request.setAttribute("title","Login");
    	request.getRequestDispatcher("login.jsp").forward(request, response);
    	   
    }
}
